package model;

import java.io.Serializable;
import java.util.ArrayList;


public class Session implements Serializable {

	private static final long serialVersionUID = 1L;
	private int day;
	private int start;
	private int end;
	public Session(int day,int start, int end) throws InvalidSessionException{
		if(end>10) throw new InvalidSessionException();
		this.day=day;
		this.start=start;
		this.end=end;
	}
	public boolean checkOverlap(Session newSession){
		if(this.equals(newSession)) return false;
		if(this.getDay()==newSession.getDay()){
			if(this.getStart()<=newSession.getStart() && newSession.getStart()<this.getEnd()) return true;
			if(this.getStart()>=newSession.getStart() && newSession.getEnd()>this.getStart()) return true;
		}
		return false;
	}
	public boolean checkOverlapList(ArrayList<Session> sessions){
		for(Session newSession:sessions){
			if (!this.equals(newSession)){
				if(this.checkOverlap(newSession)) return true;
			}
		}
		return false;
	}

	public int getDay() {
		return day;
	}

	public int getStart() {
		return start;
	}

	public int getEnd() {
		return end;
	}
	
	public String getNamedDay(){
		switch(day){
		case 1: 
			return "Sunday";
		case 2:
			return "Monday";
		case 3: 
			return "Tuesday";
		case 4:
			return "Wednesday";
		case 5: 
			return "Thursday";
		case 6:
			return "Friday";
		case 7: 
			return "Saturday";
		}
		return null;
	}
}